package com.maxjay.system.web.controller.struts;

import javax.annotation.Resource;

import com.maxjay.system.constant.YesNoConstant;
import com.maxjay.system.po.TSysUser;
import com.maxjay.system.service.BaseService;
import com.maxjay.system.service.UserService;

public class UserController extends BaseBOController {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String userId;
	
	@Resource
	private UserService userService;
	
	private TSysUser user;
	
	private String errorMsg;

	/**
	 * 显示银行卡信息
	 * 
	 * @return
	 * @author:Administrator
	 */
	public String show() {
		user = userService.getUser(userId);
		return "show";
	}
	
	public String add() {
		return "add";
	}

	public String save() {
		if(userService.validateUserExist(user.getLoginId())){
			errorMsg = "该登录名已经存在，请使用其他名字登录";
			return "add";
		}
		user.setIsManager(YesNoConstant.NO);
		saveOrValidateUpdate(user);
		return "familyUserList";
	}
	
	public String edit() {
		user = userService.getUser(userId);
		return "edit";
	}
	
	public String update(){
		user.setObjId(userId);
		saveOrValidateUpdate(user);
		return "familyUserList";
	}
	
	public String editSelfInfo() {
		user = userService.getUser(this.getCurrentUser().getObjId());
		return "editSelfInfo";
	}
	
	public String updateSelfInfo() {
		user.setObjId(userId);
		saveOrUpdate(user);
		return "editSelfInfo";
	}
	
	@Override
	protected void configPropertiesInViewState() {
		super.configPropertiesInViewState();
		this.addPropertiesInViewState("userId");
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public TSysUser getUser() {
		return user;
	}

	public void setUser(TSysUser user) {
		this.user = user;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	@Override
	protected BaseService getBaseService() {
		return this.userService;
	}

}
